package sourceagile.webservices.local;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jettison.json.JSONArray;

import sourceagile.server.localFileRepository.ListLocalFiles;
import sourceagile.webservices.GetCallback;

@SuppressWarnings("serial")
public class ListLocalFilesServlet extends HttpServlet {

	// http://localhost:8080/LiveSourceWebServices/ListLocalFilesService
	// ?projectID=flaretag

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String projectID = request.getParameter("projectID");

		JSONArray list = ListLocalFiles.listEntries(projectID);

		String answer = GetCallback.getCallback(
				request.getParameter("callback"), list.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String projectID = request.getParameter("projectID");

		JSONArray list = ListLocalFiles.listEntries(projectID);

		String answer = GetCallback.getCallback(
				request.getParameter("callback"), list.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
